﻿Public Class masalevel
    Private ALEVEL = Nothing
    Private MASLVDES = Nothing
    Private STATUS = Nothing
    Private selectMasalevel = "SELECT `alevel` AS 'รหัสความรุนแรงการแพ้ยา', `maslvdes` AS 'ความรุนแรงการแพ้ยา', `status` AS 'สถานะการเปิดใช้งาน' FROM masalevel"
    'Private selectMasgrpdrg = "SELECT GDCODE, GRPDRG, convert(bit, [STATUS]) FROM MASGRPDRG"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property ALEVEL_ As Integer
        Get
            Return ALEVEL
        End Get
        Set(value As Integer)
            ALEVEL = value
        End Set
    End Property

    Property MASLVDES_ As String
        Get
            Return MASLVDES
        End Get
        Set(value As String)
            MASLVDES = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasalevel_ As String
        Get
            Return selectMasalevel
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasalevelData()
        If connect.GetTable("SELECT alevel FROM masalevel WHERE maslvdes = '" & MASLVDES & "'").Rows.Count > 0 Then
            MsgBox("มีข้อมูลความรุนแรงการแพ้ยานี้อยู่ในระบบแล้ว")
        Else
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()
                'Dim dischargeID As Integer

                connect.ExecuteNonQuery("INSERT INTO masalevel (maslvdes, status) VALUES ('" & MASLVDES & "', '" & STATUS & "')")
                'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                MsgBox("ท่านได้ทำการเพิ่มข้อมูลการวินิจฉัยเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        End If
    End Sub

    Public Sub editMasalevelData()
        Try
            connect = CONDB.NewConnection()
            'connectlocal = conlocal.NewConnection()

            connect.ExecuteNonQuery("UPDATE masalevel SET maslvdes = '" & MASLVDES & "', status = '" & STATUS & "' WHERE alevel = '" & ALEVEL & "'")
            'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
            MsgBox("ท่านได้ทำการแก้ไขข้อมูลสถานที่เก็บยาเรียบร้อยแล้ว")
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
        End Try
        connect.Dispose()
        'connectlocal.Dispose()
    End Sub
End Class
